/*
 * Class ThievingClass
 *
 * Version 1.0
 *
 * Monday 8 December, 2008
 *
 * Created by Prima
 */

package palidino76.rs2.player.thieving;

import palidino76.rs2.*;
import palidino76.rs2.Engine;
import palidino76.rs2.npcs.*;
import palidino76.rs2.player.*;

public class ThievingClass {

	/**
	 * Constructor
	 */
	public ThievingClass(Player p) {
		this.p = p;
	}


	public void ThiefStart(Player p) {
	    NPC n = Server.engine.npcs[p.clickId];
	    p.thiefNPC = false;
		switch (p.thievingType) {

			case 1:
			    if (p.stunDelay <= 0) {
			      if (p.thiefTimer <= 0) {
			    	if (p.skillLvl[17] >= 1) {
					p.requestAnim(881, 0);
					p.thiefDelay = 3;
					p.thiefTimer = 5;
					p.frames.sendMessage(p, "You attempt to pickpocket the Man..");
			    	} else {
					p.frames.sendMessage(p, "You need to have level 1 thieving to pickpocket this Npc.");
			    	}
			      }
			    } else {
				p.frames.sendMessage(p, "You are stunned!");
			    }
					break;

			case 9:
			    if (p.stunDelay <= 0) {
			      if (p.thiefTimer <= 0) {
			    	if (p.skillLvl[17] >= 40) {
					p.requestAnim(881, 0);
					p.thiefDelay = 3;
					p.thiefTimer = 5;
					p.frames.sendMessage(p, "You attempt to pickpocket the Guard..");
			    	} else {
					p.frames.sendMessage(p, "You need to have level 40 thieving to pickpocket this Npc.");
			    	}
			      }
			    } else {
				p.frames.sendMessage(p, "You are stunned!");
			    }
					break;

		}
	}


	public void ThiefFinish(Player p) {
	    	NPC n = Server.engine.npcs[p.clickId];

		int chance = 0;
		int k = p.skillLvl[17];
		/*chance = 3 + (k - thiefLevelReq());*/

		    switch (p.thievingType) {

			case 1:
					chance = 3 + (k - 1);
				if (getRandom(chance) >= 3) {
					addItem(p, 995, 1000);
					p.frames.sendMessage(p, "You pickpocket the Man.");
					p.appendExperience(getRandom(350), 17);
				} else {
					p.frames.sendMessage(p, "You fail to pickpocket the Man.");
					p.stunDelay = 8;
					p.thiefTimer = 9;
					p.hitTimer = 2;
					n.requestAnim(422, 0);
	    			p.frames.playSound(p, 2567, 1, 0);
	    			p.frames.playSound(p, 3201, 1, 20);
					n.requestText("What do you think you're doing?!");
					n.requestFaceCoords(p.absX, p.absY);
			    	}
					break;

			case 9:
					chance = 3 + (k - 40);
				if (getRandom(chance) >= 3) {
					p.frames.sendMessage(p, "You pickpocket the Guard.");
					addItem(p, 995, 10000);
					p.appendExperience(getRandom(1400), 17);
				} else {
					p.frames.sendMessage(p, "You fail to pickpocket the Guard.");
					p.stunDelay = 8;
					p.thiefTimer = 9;
					p.hitTimer = 2;
					n.requestAnim(428, 0);
	    				p.frames.playSound(p, 2501, 1, 0);
	    				p.frames.playSound(p, 3201, 1, 20);
					n.requestText("What do you think you're doing?!");
					n.requestFaceCoords(p.absX, p.absY);
			    	}
					break;


		    }
	}

	public int thiefLevelReq() {
		switch (p.thievingType) {

			case 1:
			case 2:
			case 3:
			case 4:
			case 5:
				return 1;

			case 9:
			case 32:
				return 40;

		}
		return 0;
	}

	public int getRandom(int range) {
		return (int)(Math.random() * (range + 1));
	}

    	public static boolean addItem(Player p, int ItemId, int amt) {
        	return Engine.playerItems.addItem(p, ItemId, amt);
    	}

	Player p;
	
}